package cn.smile.config.mail;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: MaoSuyu
 * @User：John
 * @Date: 2019/5/29
 * @Time: 22:48
 * @Description: No Description
 */
@Configuration
public class JavaMailConfig {

    @Autowired
    EmailConfig emailConfig;

    @Bean
    public JavaMailSender javaMailSender() {
        JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
        //邮件服务器
        javaMailSender.setHost(emailConfig.getHost());
        //发送邮件的账号
        javaMailSender.setUsername(emailConfig.getUsername());
        //授权码
        javaMailSender.setPassword(emailConfig.getPassword());
        //编码格式
        javaMailSender.setDefaultEncoding("UTF-8");
        return javaMailSender;
    }

}
